using QFramework;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Pool;

public class CargoAPool : SingletonMono<CargoAPool>, IController
{
    [SerializeField]
    protected Transform prefab;
    [SerializeField]
    int defaultSize = 100;
    [SerializeField]
    int maxSize = 500;

    ObjectPool<Transform> pool;
    public void Initialize(bool collectionCheck = true) =>
        pool = new ObjectPool<Transform>(createFunc: OnCreatePoolItem, actionOnGet: OnGetPoolItem, actionOnRelease: OnReleasePoolItem,
            actionOnDestroy: OnDestroyPoolItem, collectionCheck: collectionCheck, defaultSize, maxSize);

    public Transform Get() => pool.Get();
    public void Release(Transform obj) => pool.Release(obj);
    public void Clear() => pool.Clear();
    protected override void Awake()
    {
        Initialize();
    }
    protected Transform OnCreatePoolItem()
    {
        prefab = this.GetModel<IGameModel>().Cargo_1200_1200_1050_Prefab.transform;
        var cargo = CreatePoolItem();
        return cargo.transform;
    }

    private Transform CreatePoolItem()
    {
        var obj = GameObject.Instantiate(this.GetModel<IGameModel>().Cargo_1200_1200_1050_Prefab);

        return obj.transform;
    }

    protected void OnGetPoolItem(Transform obj)
    {
        obj.gameObject.SetActive(true);
    }

    protected void OnReleasePoolItem(Transform obj)
    {
        obj.gameObject.SetActive(false);
    }

    protected void OnDestroyPoolItem(Transform obj)
    {
        Destroy(obj);
    }

    public IArchitecture GetArchitecture()
    {
        return DigitalTwin_GeLinMei_2.Interface;
    }
}
